package com.itheima.reggie.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.service.DishFlavorService;
import com.itheima.reggie.service.DishService;
import com.itheima.reggie.service.SetmealService;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/setmeal")
public class SetmealController {


    @Autowired
    private SetmealService setmealService;

    @Autowired
    private DishService dishService;

    @Autowired
    private DishFlavorService dishFlavorService;


    /*
    * 分页查询
    * */
    @GetMapping("/page")
    public R<Page> page(int page ,int pageSize,String name){

        log.info("page = {},pageSize = {},name = {}",page,pageSize,name);

        Page<SetmealDto> setmealDtoPage = setmealService.myPage(page,pageSize,name);

        return R.success(setmealDtoPage);

    }

    /*
    * 启售停售
    * */
    @PostMapping("/status/{status}")
    public R<String> myStatus(@PathVariable Integer status,@RequestParam List<Long> ids){
        log.info(status.toString(),ids.toString());

        setmealService.myStatus(status,ids);

        return R.success("修改成功");


    }

    /*
    * 新增套餐
    * */
    @PostMapping
    public R<String> add(@RequestBody SetmealDto setmealDto){
        log.info(setmealDto.toString());

        setmealService.mySave(setmealDto);

        return R.success("新增成功");

    }

    /*
    * 删除批量删除
    * */
    @DeleteMapping
    public R<String> delete(@RequestParam("ids") List<Long> ids){
        log.info(ids.toString());

        setmealService.myDelete(ids);

        return R.success("删除成功");

    }

    /*
    * 修改套餐信息回显数据
    * */
    @GetMapping("/{id}")
    public R<SetmealDto> getById(@PathVariable Long id){

        log.info(id.toString());

        SetmealDto setmealDto = setmealService.mygetById(id);

        return R.success(setmealDto);
    }

    /*
    * 修改套餐添加信息
    * */

    @PutMapping
    public R<String> update(@RequestBody SetmealDto setmealDto){

        log.info(setmealDto.toString());

        setmealService.myUpdate(setmealDto);

        return R.success("修改成功");
    }

    /*
    * 用于在移动端展示套餐中的菜品
    * */

    @GetMapping("/list")
    public R<List<SetmealDto>> list(Setmeal setmeal){
        log.info(setmeal.toString());

        List<SetmealDto> setmealDtos = setmealService.myList(setmeal);

        return R.success(setmealDtos);


    }





}
